package com.xo.xodemo.controller.system;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xo.xodemo.common.Result;
import com.xo.xodemo.mapper.db1.DepartmentMapper;
import com.xo.xodemo.model.Department;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/department")
public class DepartmentConttroller {
    @Autowired
    DepartmentMapper departmentMapper;
    //查找部门列表给下拉框用的
    @RequestMapping("/querydepartment1")
    @ResponseBody
    public Result departmentquery() {
        return  Result.success(departmentMapper.findAll());

    }
    @RequestMapping("/add")
    @ResponseBody
    public Result add(String departmentName) {
        return  Result.success(departmentMapper.add(departmentName));

    }
    @RequestMapping("/delete")
    @ResponseBody
    public Result delete(Integer departmentId) {
        return  Result.success(departmentMapper.delete(departmentId));

    }
    @RequestMapping("/update")
    @ResponseBody
    public Result update(Integer departmentId) {
        return  Result.success(departmentMapper.delete(departmentId));

    }
    @RequestMapping("/query")
    @ResponseBody
    public Result query(@Param("page") Integer page, @Param("limit")Integer limit, @RequestParam( value = "departmentName", defaultValue="")String departmentName) {
        PageInfo pageInfo=null;
        PageHelper.startPage(page,limit);
        pageInfo=new PageInfo(departmentMapper.query(departmentName));
        System.out.println(pageInfo);
        return  Result.success(pageInfo);

    }
}

